rem
	bbdoc: global Bullet Type
end rem
Type TBullet
	Field bBullet:Byte ptr
	Field btDynamicsWorld:Byte ptr
	Field rigidBodys:TList
	Field tempVec:bVector3
	
	Method New()
		Self.rigidBodys = New TList
		Self.tempVec	= bVector3.NullVec()
	End Method
	
	Method Delete()
		_shutDownBullet(Self.bBullet)
	End Method
	
rem
bbdoc: initialize the Simulation
endrem
	Function Init:TBullet(gravX:Float = 0.0, gravY:Float = -9.81, gravZ:Float = 0.0)
		Local bullet:TBullet 	= New TBullet
		bullet.bBullet			= _initBullet(gravX, gravY, gravZ)
		bullet.btDynamicsWorld	= _getDynamicsWorld(bullet.bBullet)
		
		Return bullet
	End Function
	
rem
bbdoc: destroys the simulation
endrem
	Method Shutdown()
		'_shutDownBullet(Self.bBullet)
	End Method
	
rem
bbdoc: adds a rigidBody to the world
endrem
	Method createRigidBody:TRigidBody(typ:Int, mass:Float, playerControlled:Byte, rbsize:bVector3, rbpos:bVector3 = Null)
		Local rigidBody:TRigidBody = Null
		
		If rbsize <> Null
			If rbpos = Null Then rbpos = bVector3.NullVec()
						
			rigidBody = TRigidBody.Create(Self, typ, mass, playerControlled, rbsize, rbpos)
			Self.rigidBodys.AddLast(rigidBody)
		EndIf
		
		Return rigidBody
	End Method
	
rem
bbdoc: returns the position of the RigidBody
endrem
	Method RigidBodyPosition:bVector3(rigidBody:TRigidBody)
		rigidBody.GetPosition(Self.tempVec)
		Return Self.tempVec
	End Method
	
rem
bbdoc: set the position of the RigidBody
endrem
	Method PositionRigidBody(rigidBody:TRigidBody, x:Float, y:Float, z:Float)
		rigidBody.SetPosition(x, y, z)
	End Method
	
rem
bboc: returns the rotation of the RigidBody
endrem
	Method RigidBodyRotation:bQuaternion(rigidBody:TRigidBody)
		Local q:bQuaternion = bQuaternion.NullVec()
		rigidBody.GetRotation(q)
		
		Return q
	End Method
		
rem
bbdoc: translate the RigidBody
endrem
	Method TranslateRigidBody(body:TRigidBody, x:Float, y:Float, z:Float)
		body.translate(x, y, z)
	End Method
	
rem
bbdoc: updates the simulation
endrem
	Method Update(timeStep:Float = 0.01666, maxSubSteps:Int = 1, fixedTimeStep:Float = 0.01666)
		_updateBullet(Self.bBullet, timeStep, maxSubSteps, fixedTimeStep)
	End Method
	
rem
bbdoc: user controlled bodies are not affected by other rigidBodies
endrem
	Method userControlledBody(body:TRigidBody)
		body.userControlledBody()
	End Method
	
rem
bbdoc: rotates the body around x axis
endrem
	Method PitchRigidBody(body:TRigidBody, x:Float)
		body.pitch(x)
	End Method
	
rem
bbdoc: rotates the body around y axis
endrem
	Method YawRigidBody(body:TRigidBody, y:Float)
		body.yaw(y)
	End Method
	
rem
bbdoc: rotates the body around z axis
endrem
	Method RollRigidBody(body:TRigidBody, z:Float)
		body.roll(z)
	End Method
End Type
